<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
    <meta id="viewport" name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no"/>
    <link rel="stylesheet" type="text/css" href="css/login.css">

    <script src="js/jquery-3.2.1.min.js"></script>


    <script>
        $(document).ready(function(){
            $("#submit2").click(function(){
                checkUser();
            });

			$('#password').keydown(function(e){
				if(e.keyCode==13){
				   checkUser();
				}
            });
            
        });
		
		function checkUser(){										
			var username = $('#username').val();
			var password = $('#password').val();
			$.get("/login",{"username":username,"password":password}
						,function(data){
								 var str = data;
								if(str.indexOf("UUID")>=0){
									setCookie('UUID',data,1);
									window.location.href='/web/upload.html';
								}else{
									 alert('账号或密码错误');
								}
						 });
			}

         //设置cookie
          function setCookie(name,value,day){
            var date = new Date();
            date.setDate(date.getDate() + day);
            document.cookie = name + '=' + value + ';expires='+ date;
          }

            //读取cookies
          function getCookie(name){
                var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
                if(arr=document.cookie.match(reg))
                return unescape(arr[2]);
                else
                return null;
           }
    </script>


</head>


<body class="sec_body" style="">


<div class="center_father">
    <h1 class="center" style="margin:0 0;font-size:x-large;padding:0;">双目人脸验证系统</h1>
</div>
<!--<form id="form1" method="post" action="/login">--> <!-- Need register RequestLoginHandler. -->
<form>
    <table align="center" cellpadding="0" cellspacing="0">
        <tr>
            <td width="100" align="right">用户:&nbsp;&nbsp;</td>
            <td width="276"><input name="username" type="text" id="username"/></td>
        </tr>
        <tr>
            <td width="100">&nbsp;&nbsp;</td>
            <td width="276">&nbsp;&nbsp;</td>
        </tr>
        <tr>
            <td align="right">密码:&nbsp;&nbsp;</td>
                <td><input name="password" type="password" id="password"  /></td>
        </tr>
        <tr>
            <td width="100">&nbsp;&nbsp;</td>
            <td width="276">&nbsp;&nbsp;</td>
        </tr>
        <tr>
            <td colspan="2" align="center">
                <input type="button" id="submit2" value="登录"/>
            </td>
        </tr>
    </table>
</form>
</body>
</html>
